package interview.data_structure;

/**
 * @author fance
 * @date 2018/7/20 14:29
 */
class TreeNode {
    public int data;
    public TreeNode left;
    public TreeNode right;

    public TreeNode(int data) {
        this.data = data;
    }
}
public class BST {
    private TreeNode root;

    public BST() {
    }
    public void insert(int data) {
        TreeNode newNode = new TreeNode(data);
        if (root == null) {
            root = newNode;
        } else {
            TreeNode cur = root;
            TreeNode parent;
            while (true) {
                parent = cur;
                if (data < cur.data) {
                    cur = cur.left;
                    if (cur == null) {
                        parent.left = newNode;
                        return;
                    }
                } else {
                    cur = cur.right;
                    if (cur == null) {
                        parent.right = newNode;
                        return;
                    }
                }
            }

        }
    }
}
